package tk.djcrazy.instantmessage.action;

import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import tk.djcrazy.instantmessage.service.IUserAvatarService;

import com.opensymphony.xwork2.ActionSupport;

public class ConfirmAvatarAction extends ActionSupport implements SessionAware {
	private static final long serialVersionUID = -5548652737358604271L;

	private boolean confirm = false;

	private IUserAvatarService userAvatarService;

	private Map<String, Object> session;

	public String execute() {
		try {
			if (confirm) {
				userAvatarService.saveUserAvatar((Integer) session.get("uid"),
						(String) session.get("avatar"));
			} else {
				session.put("avatar", "image/default.jpg");
			}
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}
	}

	public boolean isConfirm() {
		return confirm;
	}

	public void setConfirm(boolean confirm) {
		this.confirm = confirm;
	}

	public IUserAvatarService getUserAvatarService() {
		return userAvatarService;
	}

	public void setUserAvatarService(IUserAvatarService userAvatarService) {
		this.userAvatarService = userAvatarService;
	}

	public Map<String, Object> getSession() {
		return session;
	}

	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

}
